import Vue from 'vue'
import Router from 'vue-router'
import store from "@/store";
import utils from "@/utils/utils.js";
import splitUrl from '@/utils/splitUrl.js';
import App from "@/App";
/*****************************公共start*****************************/
//半圆对比评分
const dataObj = r => require.ensure([], () => r(require('@/pages/dataObj.vue')))
const chartDemo = r => require.ensure([], () => r(require('@/pages/chartDemo.vue')))
const pk = r => require.ensure([], () => r(require('@/pages/pk.vue')))
const notes = r => require.ensure([], () => r(require('@/pages/notes.vue')))
const swipterEffects = r => require.ensure([], () => r(require('@/pages/swipterEffects.vue')))
const zan = r => require.ensure([], () => r(require('@/pages/zan.vue')))
const drag = r => require.ensure([], () => r(require('@/pages/drag.vue')))
const barrage = r => require.ensure([], () => r(require('@/pages/barrage.vue')))
// 大转盘
const bigWheel = r => require.ensure([], () => r(require('@/pages/bigWheel.vue')))
// Vue无缝滚动
const vueScroll = r => require.ensure([], () => r(require('@/pages/vueScroll.vue')))
// 缓存
const listIndex = r => require.ensure([], () => r(require('@/pages/listIndex.vue')))
const listData = r => require.ensure([], () => r(require('@/pages/listData.vue')));

const details = r => require.ensure([], () => r(require('@/pages/details.vue')))
const playMusicIndex = r => require.ensure([], () => r(require('@/pages/playMusicIndex.vue')))
const showPdf = r => require.ensure([], () => r(require('@/pages/showPdf.vue')))

const vuefullPage = r => require.ensure([], () => r(require('@/pages/vuefullPage.vue')))

const readPdf = r => require.ensure([], () => r(require('@/pages/readPdf.vue')))
const waterMark = r => require.ensure([], () => r(require('@/pages/waterMark.vue')))
const searchInput = r => require.ensure([], () => r(require('@/pages/searchInput.vue')))
const selAddTr = r => require.ensure([], () => r(require('@/pages/selAddTr.vue')))

//保存图片
const savePhoto = r => require.ensure([], () => r(require('@/pages/savePhoto.vue')));
const pdfjs = r => require.ensure([], () => r(require('@/pages/pdfjs.vue')));
const pdfh5 = r => require.ensure([], () => r(require('@/pages/pdfh5.vue')));
const filterData = r => require.ensure([], () => r(require('@/pages/filterData.vue')));
const pdfjsDist = r => require.ensure([], () => r(require('@/pages/pdfjsDist')));
const copyandEye = r => require.ensure([], () => r(require('@/pages/copyandEye.vue')))
/************************************* 答题
活动 end ******************************************** */

Vue.use(Router)
const router = new Router({
    mode: 'history',
    routes: [{
            path: '/',
            redirect: '/swipterEffects'
        },
        {
            path: '/selAddTr',
            name: 'selAddTr',
            component: selAddTr,
            meta: {
                title: 'select表单增行'
            }
        },
        {
            path: '/bigWheel',
            name: 'bigWheel',
            component: bigWheel,
            meta: {
                title: '抽奖大转盘'
            }
        },


        {
            path: '/searchInput',
            name: 'searchInput',
            component: searchInput,
            meta: {
                title: '搜索文字过滤'
            }
        },

        {
            path: '/swipterEffects',
            name: 'swipterEffects',
            component: swipterEffects,
            meta: {
                title: 'swipter双层联动'
            }
        },
        {
            path: '/zan',
            name: 'zan',
            component: zan,
            meta: {
                title: '动画点赞'
            }
        },
        {
            path: '/chartDemo',
            name: 'chartDemo',
            component: chartDemo,
            meta: {
                title: '各种图表'
            }
        },

        {
            path: '/pk',
            name: 'pk',
            component: pk,
            meta: {
                title: 'pk'
            }
        },
        {
            path: '/notes',
            name: 'notes',
            component: notes,
            meta: {
                title: '笔记'
            }
        },
        {
            path: '/dataObj',
            name: 'dataObj',
            component: dataObj,
            meta: {
                title: 'dataObj'
            }
        },
        {
            path: '/drag',
            name: 'drag',
            component: drag,
            meta: {
                title: '拖动'
            }
        },
        {
            path: '/barrage',
            name: 'barrage',
            component: barrage,
            meta: {
                title: '弹幕'
            }
        },
        {
            path: '/vueScroll',
            name: 'vueScroll',
            component: vueScroll,
            meta: {
                title: 'Vue无缝滚动'
            }
        },

        {
            path: '/vueScroll',
            name: 'vueScroll',
            component: vueScroll,
            meta: {
                title: 'Vue无缝滚动'
            }
        },
        {
            path: '/listIndex',
            name: 'listIndex',
            component: listIndex,
            children: [{
                path: '/',
                name: 'listData',
                component: listData,
                meta: {
                    title: '缓存-列表页',
                    // keepAlive: true,
                    // isBack: false,
                }
            }],
        }, {
            path: '/details',
            name: 'details',
            component: details,
            meta: {
                title: '缓存-详情',
            }
        }, {
            path: '/playMusicIndex',
            name: 'playMusicIndex',
            component: playMusicIndex,
            meta: {
                title: '播放音乐',
            },
        },
        {
            path: '/showPdf',
            name: 'showPdf',
            component: showPdf,
            meta: {
                title: 'pdf展示-swiper',
            },
        }, {
            path: '/vuefullPage',
            name: 'vuefullPage',
            component: vuefullPage,
            meta: {
                title: 'vuefullPage',
            },
        },
        {
            path: '/readPdf',
            name: 'readPdf',
            component: readPdf,
            meta: {
                title: 'readPdf',
            },
        }, {
            path: '/savePhoto',
            name: 'savePhoto',
            component: savePhoto,
            meta: {
                title: 'H5页转成图片demo',
            }
        }, {
            path: '/waterMark',
            name: 'waterMark',
            component: waterMark,
            meta: {
                title: 'waterMark',
            },
        }, {
            path: '/pdfh5',
            name: 'pdfh5',
            component: pdfh5,
            meta: {
                title: 'pdfh5',
            }
        },
        {
            path: '/pdfjs',
            name: 'pdfjs',
            component: pdfjs,
            meta: {
                title: 'pdfjs',
            }
        },
        {
            path: '/filterData',
            name: 'filterData',
            component: filterData,
            meta: {
                title: 'filterData',
            }
        },
        {
            path: '/copyandEye',
            name: 'copyandEye',
            component: copyandEye,
            meta: {
                title: 'copyandEye',
            }
        },
        // {
        //     path: '/pdfjsDist',
        //     name: 'pdfjsDist',
        //     component: pdfjsDist,
        //     meta: {
        //         title: 'pdfjsDist',
        //     }
        // },
    ]
})
// 全局路由守卫
router.beforeEach((to, from, next) => {
    // 如果未匹配到路由
    if (to.matched.length === 0) {
        from.path ? next({
            path: from.path
        }) : next('/')
    } else {
        // 设置埋点title
        if (to.meta && to.meta.title) {
            document.title = to.meta.title
        }
        next()
    }
});

export default router
